package com.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import com.feignclient.IMallAService;

@RestController
@RequestMapping("/mall/b/api")
public class MallBContoller {

    @Autowired
    private IMallAService provider;

    @GetMapping("/")
    public String init(HttpServletRequest request) {
        return "this is mall b " + request.getLocalAddr() + "," + request.getLocalPort();
    }

    @GetMapping("/test")
    public String getATest(HttpServletRequest request) {
        return "mall b test() " + request.getLocalAddr() + "," + request.getLocalPort();
    }

    @GetMapping("/port")
    public String getProt() {
        RequestAttributes ra = RequestContextHolder.getRequestAttributes();
        ServletRequestAttributes sra = (ServletRequestAttributes)ra;
        HttpServletRequest request = sra.getRequest();
        return request.getLocalAddr() + ":" + request.getLocalPort();
    }

    /**
     * 通过feign调用mall a服务接口
     * 
     * @return
     */
    @GetMapping("/call/mall/a/user")
    public String getInfo() {
        return provider.userInfo();
    }
}
